<?php

namespace Frieza\Modules\FeaturePosition\Actions;

use Encore\Admin\Actions\RowAction;
use Illuminate\Http\Request;
use Doraemon\model\FeatureModuleInfo;

class DeleteFeature extends RowAction
{
    public $name = '删除模块';
    const TOAST_ALERT = '是否删除该模块,删除后将不再展示?';

    public function handle($id)
    {
        $data['data_status'] = FeatureModuleInfo::STATUS_DELETE;
        $result = FeatureModuleInfo::updateData($data, ['id' => $id]);
        if ($result) {
            return $this->response()->success('删除模块成功!')->refresh();
        }else{
            return $this->response()->error('删除模块失败,请稍后重试!!');
        }
    }

    public function retrieveModel(Request $request)
    {
        if (!$key = $request->get('_key')) {
            return false;
        }

        return $key;
    }

    public function dialog()
    {
        $this->confirm(self::TOAST_ALERT);
    }
}
